//
//  TabBarViewController.m
//  yemeishe1
//
//  Created by 吴坤金 on 2017/2/28.
//  Copyright © 2017年 yameishe. All rights reserved.
//

#import "TabBarViewController.h"
#import "CenterViewController.h"
#import "LeftViewController.h"
#import "LoginTranslation.h"
#import "TaskViewController.h"
#import "MemberViewController.h"
#import "OrderViewController.h"


@interface TabBarViewController ()<UIViewControllerTransitioningDelegate
>
@property (nonatomic, strong) MMDrawerController *drawerController;

@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self addChildVC];
    [self setupTabBarItem];
}

+(void)load {
    //    获取所有的TabBarItem
    UITabBarItem *item = [UITabBarItem appearance];
    
    //    用一个字典描叙富文本属性
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    //    描叙标题颜色
    dic[NSForegroundColorAttributeName] = [UIColor blackColor];
    [item setTitleTextAttributes:dic forState:UIControlStateSelected];
    //    描叙字体
    dic = [NSMutableDictionary dictionary];
    //    设置大小
    dic[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    [item setTitleTextAttributes:dic forState:UIControlStateNormal];
    


   
}


- (void)addChildVC {
//    1.添加首页控制器
    // 初始化控制器
    UIViewController *centerVc = [[CenterViewController alloc] init];
    centerVc.transitioningDelegate = self;
    LeftViewController *leftVc = [[LeftViewController alloc] init];
    leftVc.transitioningDelegate = self;
    [leftVc setCallbackDidSelect:^{
        [self.drawerController closeDrawerAnimated:YES completion:^(BOOL finished) {
            
        }];
    }];
    
    // 初始化导航控制器
    UINavigationController *centerNav = [[UINavigationController alloc] initWithRootViewController:centerVc];
 
    UINavigationController *leftNav = [[UINavigationController alloc] initWithRootViewController:leftVc];
    
    self.drawerController = [[MMDrawerController alloc] initWithCenterViewController:centerNav leftDrawerViewController:leftNav];
    self.drawerController.transitioningDelegate = self;
    
    [self.drawerController setShowsShadow:YES];
    [self.drawerController setMaximumLeftDrawerWidth:SCREEN_WIDTH * 0.75];
    [self.drawerController setMaximumRightDrawerWidth:SCREEN_WIDTH * 0.75];
    [self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
    [self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeTapCenterView];
    [self addChildViewController:self.drawerController];
    
    
//    2.添加任务管理器
    TaskViewController *taskVC = [[TaskViewController alloc] init];
    taskVC = [[UIStoryboard storyboardWithName:@"Task" bundle:nil] instantiateViewControllerWithIdentifier:@"TaskViewController"];
    UINavigationController *Nav1 = [[UINavigationController alloc] initWithRootViewController:taskVC];
    [self addChildViewController:Nav1];
    
//    3.添加订单控制器
    OrderViewController *orderVC = [[OrderViewController alloc] init];
    UINavigationController *Nav2 = [[UINavigationController alloc] initWithRootViewController:orderVC];
    [self addChildViewController:Nav2];
    
//    4.会员中心
    MemberViewController *memberVC = [[MemberViewController alloc] init];
    memberVC = [[UIStoryboard storyboardWithName:@"Member" bundle:nil] instantiateViewControllerWithIdentifier:@"MemberViewController"];
    UINavigationController *Nav3 = [[UINavigationController alloc] initWithRootViewController:memberVC];
    [self addChildViewController:Nav3];
    
}


- (void)setupTabBarItem {
    UIViewController *vc = self.childViewControllers[0];
    vc.tabBarItem.title = @"首页";
//    vc.tabBarItem.image = [UIImage imageNamed:@"home"];
//    vc.tabBarItem.selectedImage = [UIImage imageNamed:@"home-seleted"];
    
    UIViewController *vc2 = self.childViewControllers[1];
    vc2.tabBarItem.title = @"任务管理";
    
    UIViewController *vc3 = self.childViewControllers[2];
    vc3.tabBarItem.title = @"订单中心";
    
    
    UIViewController *vc4 = self.childViewControllers[3];
    vc4.tabBarItem.title = @"会员中心";
    
}
-(void)viewWillDisappear:(BOOL)animated {
    // 反注册键盘
    [super viewWillDisappear:YES];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
